<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* @function rem($px) {
   @return $px / 750 * 10rem;
 } */
        /* scss中使用 */

        div {
            background-color: red;
            width: 1rem;
            height: 1rem;
        }
    </style>
</head>

<body>
    <div></div>
</body>
<script>
    function setRem() {
        const htmlEl = document.documentElement;
        const htmlWidth = htmlEl.clientWidth;
        const htmlFontSize = htmlWidth / 10;
        htmlEl.style.fontSize = htmlFontSize + 'px';
        console.log(htmlEl.style.fontSize, 'day...........');
    };
    // 第一次进入页面调用
    setRem();
    window.addEventListener('resize', setRem);
</script>

</html>